<?php

namespace Modules\User\Entities;

use Modules\Core\Entities\BaseEntity as Model;

// 收货地址
class Address extends Model
{
    protected $guarded = [];
    protected $table = 'addresses';

    static public $resourceName = '地址';

    // 其它地址
    public function brotherAddresses()
    {
    	return $this->hasMany('\Modules\User\Entities\Address', 'user_id', 'user_id')->where('id', '<>', $this->id);
    }

    // 设置为默认
    public function setDefault()
    {
    	if ($this->is_default !== 1) {
	    	$this->is_default = 1;
	    	$this->save();
    	}

    	$this->brotherAddresses()->update([
    		'is_default' => 0
    	]);
    }
}
